﻿#include "cfilestoragelib.h"
#include "cfilestorageimpl.h"

void *createInstance()
{
    return new CFileStorageImpl();
}

void destoryInstance(void *obj)
{
    CFileStorageImpl *ptr = (CFileStorageImpl *)obj;
    if (ptr)
    {
        delete ptr;
    }
}

void doSetServiceAddress(void *obj, std::string url)
{
    CFileStorageImpl *ptr = (CFileStorageImpl *)obj;
    if (ptr)
    {
        ptr->setServiceAddress(url);
    }
}

bool doPushFile(void *obj, const std::string &localPath, const std::string &remotePath)
{
    CFileStorageImpl *ptr = (CFileStorageImpl *)obj;
    if (ptr)
    {
        return ptr->pushFile(localPath, remotePath);
    }

    return false;
}

bool doPullFile(void *obj, const std::string &localPath, const std::string &remotePath)
{
    CFileStorageImpl *ptr = (CFileStorageImpl *)obj;
    if (ptr)
    {
        return ptr->pullFile(localPath, remotePath);
    }

    return false;
}

bool doPushData(void *obj, const std::vector<uint8_t> &localData, const std::string &remotePath)
{
    CFileStorageImpl *ptr = (CFileStorageImpl *)obj;
    if (ptr)
    {
        return ptr->pushData(localData, remotePath);
    }

    return false;
}

bool doPullData(void *obj, std::vector<uint8_t> &localData, const std::string &remotePath)
{
    CFileStorageImpl *ptr = (CFileStorageImpl *)obj;
    if (ptr)
    {
        return ptr->pullData(localData, remotePath);
    }

    return false;
}

std::string doGetLastErrorText(void *obj)
{
    CFileStorageImpl *ptr = (CFileStorageImpl *)obj;
    if (ptr)
    {
        return ptr->getLastErrorText();
    }

    return "你输入的对象为空";
}
